import java.util.*;

public class Zoo {
	public long theCount(int[] answers) {
        SortedMap<Integer, Integer>  ans = new TreeMap<Integer, Integer>();
        for (int current: answers){
            if (ans.containsKey(current)){
                ans.put(current, ans.get(current) + 1);
            }
            else{
                ans.put(current, 1);
            }
        }
        long ret = 0;
        int minCount = Integer.MAX_VALUE;
        int prev = ans.firstKey(), prevCount = ans.get(prev);
        minCount = Math.min(prevCount, minCount);
        ans.remove(prev);
        if (prev != 0 || prevCount > 2) {
            return 0;
        }
        ret = 1;
        ret *= prevCount;
        while (ans.size() != 0){
            int cur = ans.firstKey(), curCount = ans.get(cur);
            minCount = Math.min(prevCount, curCount);
            if (prev != cur - 1 || curCount > prevCount){
                return 0;
            }
            ret *= curCount;
            prev = cur;
            prevCount = curCount;
            ans.remove(prev);
        }
        if (minCount < 2){
            ret <<= 1;
        }
        return ret;
  }
}
